<template>
  <el-card class="elcard" style="flex:1;align-self:normal;">
    <div slot="header" class="hd clearfix">
      <p class="tit">任职单位：<span>{{total}}</span>个</p>
    </div>
    <el-table
      :data="data"
      border
      style="width: 100%;"
      :header-row-class-name="headerRowClassName"
      :header-cell-style="patentHeaderStyle"
      :row-class-name="tableRowClassName"
      :cell-style="patentCellStyle"
      :empty-text="emptyText">
      <el-table-column
        type="index"
        label="序号"
        width="70"
        align="center">
      </el-table-column>
      <el-table-column
        prop="name"
        label="企业名称"
        width="400">
        <template slot-scope="scope">
          <p class="company-name"><i class="iconfont icon-jigouxinxi"></i><span>{{scope.row.name}}</span></p>
        </template>
      </el-table-column>
      <el-table-column
        prop="position"
        label="职位">
      </el-table-column>
      <el-table-column
        prop="regist_capi"
        label="注册资本">
      </el-table-column>
      <el-table-column
        prop="province"
        label="地区">
      </el-table-column>
      <!-- <el-table-column
        prop="category"
        label="行业">
      </el-table-column> -->
      <el-table-column
        prop="status"
        label="状态"
        width="220">
        <template slot-scope="scope">
          <p :class="['status', statusColor(scope.row.status)]">{{scope.row.status}}</p>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
      info: {},
      data: [],
      total: '',
      headerRowClassName: () => {
        return 'thead-tr'
      },
      patentHeaderStyle: function(){
        return 'font-weight: 600; color: #241c75;'
      },
      patentCellStyle: function() {
        return 'color: #7674a3'
      },
      emptyText: '数据加载中...'
    }
  },
  computed: {
    statusColor() {
      return function(status) {
        if (status.indexOf('存续') > -1) {
          return 'green'
        } else if (status.indexOf('销') > -1) {
          return 'red'
        } else {
          return ''
        }
      }
    }
  },
  methods: {
    init() {
      this.info = {
        name: this.$route.query.name,
        key: this.$route.query.key,
        companyName: this.$route.query.companyName
      }
      this.getData()
    },
    // 获取任职单位信息
    getData() {
      this.emptyText = '数据加载中...'
      this.$get(this.$Url.team.getCompaniesInfoAsEmployee, {
        pid: this.info.key
      }).then(res => {
        let data = res.data
        data.forEach(v => {
          if (v.regist_capi === '') v.regist_capi = '-'
          if (!v.sharehdratio || v.sharehdratio === '') v.sharehdratio = '-'
        })
        if (data.length <= 0) {
          this.emptyText = '暂无数据'
        }
        this.data = data
        this.total = data.length || 0
      }).catch(err => {
        this.emptyText = '暂无数据'
        this.total = 0
      })
    },
    tableRowClassName({row, rowIndex}) {
      if (rowIndex % 2) {
        return 'warning-row';
      } 
      return '';
    },
  },
  mounted() {
    this.init()
  }
}
</script>

<style lang="scss" scoped>
.el-table {
  ::v-deep {
    .thead-tr {
      th {
        border-right: 0;
        color: $color126 !important;
        background-color: $color128;
      }
    }
  }
  .company-name {
    position: relative;
    display: flex;
    align-items: center;
    color: $color127;
    i {
      display: inline-block;
      width: 30px;
      height: 30px;
      line-height: 30px;
      border-radius: 4px;
      margin-right: 6px;
      text-align: center;
      font-size: 16px;
      vertical-align: middle;
      color: $color2;
      background-color: $mainColor;
    }
    span {
      display: inline-block;
      width: calc(100% - 36px);
      // line-height: 30px;
      vertical-align: middle;
    }
  }
  .status {
    display: inline-block;
    padding: 4px 10px;
    color: $color62;
    background-color: rgba(255,236,202,.5);
    &.green {
      color: $color60;
      background-color: rgba(47,200,144,.2);
    }
    &.red {
      color: $color81;
      background-color: rgba(245,108,108,.2);
    }
  }
}
</style>